package com.livelab.model;

import com.livelab.util.Constant;
import java.sql.Timestamp;

/**
 * Relational Database Utility Class: AssignedExercise
 * 
 * @author Dakota
 */
public class AssignedExercise {
    private String assignedBy;      //instructor username
    private String exerciseName;    //exercise name
    private Timestamp whenCreated;  //creation timestamp
    private Timestamp dueDate;      //due date timestamp
    private double score;           //max score of exercise
    
    /**
     * Constructor
     * 
     * @param assignedBy -- Instructor username
     * @param exerciseName -- Exercise name
     */
    public AssignedExercise(String assignedBy, String exerciseName){
        this.assignedBy = assignedBy;
        this.exerciseName = exerciseName;
        java.util.Date today = new java.util.Date();
        whenCreated = new java.sql.Timestamp(today.getTime());
        
        //set default due date one week from current date
        dueDate = new java.sql.Timestamp(today.getTime() + Constant.ONE_WEEK);
        score = 10.0;
    }
    
    /**
     * Constructor
     * 
     * @param assignedBy -- Instructor username
     * @param exerciseName -- Exercise name
     * @param whenCreated -- Creation timestamp
     * @param dueDate -- Due date timestamp
     * @param score -- Max score value of Exercise
     */
    public AssignedExercise(String assignedBy, String exerciseName, Timestamp whenCreated, Timestamp dueDate, double score ){
         this.assignedBy = assignedBy;
         this.exerciseName = exerciseName;
         this.whenCreated = whenCreated;
         this.dueDate = dueDate;
         this.score = score;
    }
    
    /**
     * Returns a new AssinedExercise with a specified due date
     * @param date -- new due date
     * @return -- AssignedExercise with new due date
     */
    public AssignedExercise extendDate(java.util.Date date){
        return new AssignedExercise(assignedBy, exerciseName, whenCreated, new Timestamp(date.getTime()), score);
    }
     
    /*
     * GETTERS
     */
    
    public String getAssignedBy(){
        return assignedBy;
    }
    
    public String getDueDate(){
        return dueDate.toString();
    }
    
    public Timestamp getTimeStampDue(){
        return dueDate;
    }
    
    public String getExerciseName(){
        return exerciseName;
    }
    
    public String getScore(){
        return Double.toString(score);
    }
    
    public String getWhenCreated(){
        return whenCreated.toString();
    }
    
    public boolean isPastDue(){
        return dueDate.before(new java.util.Date());
    }
    
    /*
     * SETTERS
     */
    
    public void setScore(String score){
        this.score = Double.parseDouble(score);
    }
    
    public void setDueDate(String date){
        this.dueDate = Timestamp.valueOf(date);
    }
    
    /**
     * Converts attributes to array in specific order used by a PreparedStatment
     * 
     * @return 
     */
    public Object[] toArray(){
        return new Object[]{assignedBy, exerciseName, whenCreated, dueDate, score};
    }
}
